﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Microsoft.Popfly.GameCreator.GameEngine.Behaviors
{
    public static class BehaviorFactory
    {
        public static IBehavior CreateBehavior(Game game, BehaviorOwner owner, Data.BehaviorInfo behaviorInfo)
        {
            Type behaviorType = behaviorInfo.GetType();
            if (behaviorType.Equals(typeof(Data.MotionBehaviorInfo)))
            {
                return MotionBehaviorFactory.CreateMotionBehavior(game, owner, ((Data.MotionBehaviorInfo)behaviorInfo).Motion);
            }
            else if (behaviorType.Equals(typeof(Data.PropertyChangeBehaviorInfo)))
            {
                return PropertyBehaviorFactory.CreatePropertyBehavior(game, owner, behaviorInfo);
            }
            else if (behaviorType.Equals(typeof(Data.CustomBehaviorInfo)))
            {
#if PHONE
                return new SoundBehavior(game, "errorbeep.wma");
#else
                return new CustomBehavior(owner, game, ((Data.CustomBehaviorInfo)behaviorInfo).Code);
#endif
            }
            else if (behaviorType.Equals(typeof(Data.DisappearBehaviorInfo)))
            {
                return new DisappearBehavior(game, owner, behaviorInfo);
            }
            else if (behaviorType.Equals(typeof(Data.AppearBehaviorInfo)))
            {
                return AppearBehaviorFactory.CreateAppearBehavior(game, owner, behaviorInfo);
            }
            else if (behaviorType.Equals(typeof(Data.SceneChangeBehaviorInfo)))
            {
                return new SceneChangeBehavior(game, ((Data.SceneChangeBehaviorInfo)behaviorInfo).SceneName);
            }
            else if (behaviorType.Equals(typeof(Data.StateChangeBehaviorInfo)))
            {
                return new StateChangeBehavior(owner, behaviorInfo);
            }
            else if (behaviorType.Equals(typeof(Data.BulletBehaviorInfo)))
            {
                return new ShootBehavior(game, owner, (Data.BulletBehaviorInfo)behaviorInfo);
            }
            else
            {
                throw new NotImplementedException(
                    Utils.ErrorMessagePrefix +
                    "The behaviorType used: '" +
                    behaviorType.ToString() +
                    "' has not yet been implemented by EventListener's constructor."
                    );
            }
        }
    }
}
